package router

import (
	"blog/app/http"
	"blog/app/http/api"
	"blog/core/request"

	"github.com/gin-gonic/gin"
)

type Interface interface {
	Load(router *gin.Context)
}

type Router struct {
}

type req func(request.InterfaceRequest)

func (router *Router) handFunc(h req) gin.HandlerFunc {
	return func(ctx *gin.Context) {
		h(request.Request(ctx))
	}
}

func (router *Router) Load(g *gin.Engine) {
	group := g.Group("go")
	group.POST("upload", api.Upload)
	group.GET("FileList", router.handFunc(api.GetLists))
	router.ping(group)
	router.article(group)
	router.login(group)
	router.admin(group)
	router.album(group)
	router.system(group)
	router.file(group)
	router.config(group)
}

func (router *Router) ping(g *gin.RouterGroup) {
	ping := g.Group("ping")
	{
		ping.GET("/", http.Ping)
	}
}

func (router Router) system(g *gin.RouterGroup) {
	system := g.Group("system")
	api := http.ApiGroup.SystemApi
	{
		system.GET("info", router.handFunc(api.GetInfo))
		system.GET("toDay", router.handFunc(api.PhotoOfTheDay))
	}
}
